package com.game.league.task.detail.panel;

import android.app.Activity;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.game.base.app.base.BasePanel;
import com.game.league.R;
import com.game.league.databinding.PanelTaskStepBinding;
import com.game.league.task.detail.adapter.StepDetailAdapter;
import com.game.league.task.table.Task;
import com.game.league.util.SkipUtil;

import java.util.ArrayList;

/**
 * Created by Su on 2019/6/6.
 */
public class StepPanel extends BasePanel<PanelTaskStepBinding> {
    private StepDetailAdapter alertAdapter, stepAdapter;
    private Task task = SkipUtil.currentTask;

    @Override
    protected int getLayoutId() {
        return R.layout.panel_task_step;
    }

    public StepPanel(Activity activity) {
        super(activity);
        initView();
    }

    private void initView() {

        // 任务须知
        binding.recyclerAlert.setLayoutManager(new LinearLayoutManager(activity));
        alertAdapter = new StepDetailAdapter(activity, 1);
        binding.recyclerAlert.setAdapter(alertAdapter);

        // 详细步骤
        binding.recyclerStep.setLayoutManager(new LinearLayoutManager(activity));
        stepAdapter = new StepDetailAdapter(activity, 2);
        binding.recyclerStep.setAdapter(stepAdapter);
    }

    public void refreshData() {
        if (task.getAlert() == null || task.getAlert().isEmpty()) {
            binding.tvAlertIco.setVisibility(View.GONE);
            binding.recyclerAlert.setVisibility(View.GONE);
        } else {
            alertAdapter.setItems((ArrayList<String>) task.getAlert());
        }

        if (task.getStep() == null || task.getStep().isEmpty()) {
            binding.tvStepTitle.setVisibility(View.GONE);
            binding.recyclerStep.setVisibility(View.GONE);
        } else {
            stepAdapter.setItems((ArrayList<String>) task.getStep());
        }
    }
}
